﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.Runtime.InteropServices;
namespace MianShi
{
    public class ProcessManager
    {
        public static void KillProcess(DateTime startDateTime,DateTime endDateTime,string processName)
        {
            Process[] thisProcess = Process.GetProcessesByName(processName);
            if (thisProcess.Length > 0)
            {
                for (int i = 0; i < thisProcess.Length; i++)
                {
                    try
                    {
                        if (thisProcess[i].StartTime >= startDateTime && thisProcess[i].StartTime <= endDateTime)
                        {
                            thisProcess[i].Kill();
                        }//结束进程  
                    }
                    catch (Exception ex)
                    {
                        GC.Collect();
                    }
                }
            }
        }  
    }
}
